<template>
    <div class="app-container calendar-list-container" v-loading="loading" element-loading-text="正在导出数据">
    <!-- filter 条件查询 -->
    <div class="btn-add">
        <el-button
        icon="el-icon-circle-plus-outline"
        type="button"
        class="el-button el-button--primary"
        @click="addInOrOut"
        >
            新增</el-button
        >
    </div>

    <!-- 新增数据弹窗 -->
    <el-dialog
      title="新增"
      :visible.sync="showAdd"
      @close="showAdd = false"
      width="70%"   
    >
        <el-form :model="createForm" :inline="true" ref="createForm" :rules="addRules">
            <div style="display: flex;">
                <el-form-item label="工作中心" prop="workCenter" label-width="120px">
                    <!-- @focus="getCenterList"  -->
                    <el-select 
                        v-model="createForm.workCenter" 
                        clearable
                        filterable
                        placeholder="请选择工作中心"
                        class="ul-item">
                        <el-option :value="item" :label="item" v-for="(item,index) in this.centerList" :key="index"/>
                    </el-select>
                </el-form-item>
                <el-form-item label="检验环节" prop="inspectionLink" label-width="120px">
                    <el-select filterable clearable v-model="createForm.inspectionLink" placeholder="请选择检验环节">
                       <el-option :value="item" :label="item" v-for="(item,index) in this.processList" :key="index"/>
                    </el-select>
                    <!-- <el-input v-model="createForm.inspectionLink" placeholder="请输入检验环节" autosize style="width: 150px"/> -->
                </el-form-item>
                <el-form-item label="编码类别" prop="codingClass" label-width="120px">
                    <el-input v-model="createForm.codingClass" placeholder="请输入编码类别" autosize style="width: 150px"/>
                </el-form-item>
                <el-form-item label="检验方式" prop="inspectionMethod" label-width="120px">
                    <el-select v-model="createForm.inspectionMethod" placeholder="请选择检验方式" class="ul-item" filterable clearable style="width: 150px">
                      <el-option v-for="(item,index) in checkoutList" :key="index" :label="item" :value="item"> </el-option>
                    </el-select>
                </el-form-item>
            </div>
            <div style="display: flex;">
                <el-form-item label="抽检状态"  prop="samplingStatus" v-if="createForm.inspectionMethod != '全检'" label-width="120px">
                    <el-select v-model="createForm.samplingStatus" placeholder="请选择抽检状态" class="ul-item" filterable clearable style="width: 150px">
                        <el-option v-for="(item,index) in samplingStatusList" :key="index" :label="item" :value="item"> </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="查检表" prop="checkList" label-width="120px">
                    {{ '停用' }}
                    <el-switch  v-model="createForm.checkList" active-value="启用" inactive-value="停用" />
                    {{ '启用' }}
                </el-form-item>
                <el-form-item label="查检方式" v-if="createForm.checkList == '启用'" prop="inspectionMode">
                    <el-select v-model="createForm.inspectionMode" placeholder="请选择查检方式" class="ul-item" filterable clearable style="width: 150px">
                        <el-option v-for="(item,index) in InspectionList" :key="index" :label="item" :value="item"> </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="拍照存档" prop="mugShot" label-width="120px">
                    {{ '否' }}
                    <el-switch  v-model="createForm.mugShot" active-value="是" inactive-value="否" />
                    {{ '是' }}
                </el-form-item>
                <el-form-item label="拍照方式" v-if="createForm.mugShot == '是'" prop="photoMethod">
                    <el-select v-model="createForm.photoMethod" placeholder="拍照方式" class="ul-item" filterable clearable style="width: 130px">
                        <el-option v-for="(item,index) in InspectionList" :key="index" :label="item" :value="item"> </el-option>
                    </el-select>
                </el-form-item>
            </div>
            <div>
                <el-link  v-if="createForm.inspectionMethod != '全检'" :underline="false" style="margin-right: 20px;">抽检方案维护</el-link>
                <el-button  v-if="createForm.inspectionMethod != '全检'" type="primary" @click="SchemeAdd" icon="el-icon-plus" circle></el-button>
                <div style="display: flex">
                  <div style="width: 800px;margin-top:15px;"  v-if="createForm.inspectionMethod != '全检'">
                    <el-table  :data="SchemeList" stripe border fit highlight-current-row style="width: 800px;margin-top:15px;">
                        <el-table-column  label="序号" type="index" align="center" width="50px"/>
                        <el-table-column label="数量大于" align="center" width="130">
                            <template slot-scope="scope">
                                <el-input v-model.number="scope.row.beGreaterThan" autosize style="width: 100px"/>
                        </template>
                    </el-table-column>
                    <el-table-column label="数量小于等于" align="center" width="130">
                        <template slot-scope="scope">
                            <el-input v-model.number="scope.row.quantityLe" autosize style="width: 100px"/>
                        </template>
                    </el-table-column>
                    <el-table-column label="放宽检验数量" align="center" width="130">
                        <template slot-scope="scope">
                            <el-input v-model.number="scope.row.relaxTheNumberOfRandomInspections" autosize style="width: 100px"/>
                        </template>
                    </el-table-column>
                    <el-table-column label="正常检验数量" align="center" width="130">
                        <template slot-scope="scope">
                            <el-input v-model.number="scope.row.normalSamplingQuantity" autosize style="width: 100px"/>
                        </template>
                      </el-table-column>
                      <el-table-column label="加严检验数量" align="center" width="130">
                        <template slot-scope="scope">
                            <el-input v-model.number="scope.row.increaseTheNumberOfRandomInspections" autosize style="width: 100px"/>
                        </template>
                      </el-table-column>
                      <el-table-column align="center" width="50">
                          <template slot-scope="scope">
                              <el-button type="danger" @click="SchemeDel(scope.$index,scope.row)" icon="el-icon-delete" circle></el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                  </div>
                    <el-form-item label="邮件抄送" label-width="80px">
                        <div v-for="(items,index1) in MailUserName" :key="index1" style="margin-bottom: 5px;">
                            <el-select  @change="mailChang($event,index1)" filterable @focus="businessFocus" v-model="items.name" placeholder="请选择" style="width:150px">
                                <el-option
                                v-for="(item,index) in personnelList"
                                :key="index"
                                :label="item.userName"
                                :value="item.userName">
                            </el-option>
                        </el-select>
                        <el-button style="margin-left: 5px;" type="danger" icon="el-icon-delete" circle @click="delMail(index1)"></el-button>
                        <el-button v-if="index1 == 0" style="margin-left: 5px;" type="primary" icon="el-icon-plus" circle @click="addMail"></el-button>
                        </div>
                   </el-form-item>
                </div>
            </div>
        </el-form>
        <div v-if="createForm.inspectionMethod != '全检'">
            <el-link :underline="false" style="margin-top: 15px;">检验转移方案</el-link>
            <el-table :data="transfer" stripe border fit highlight-current-row style="width: 100%;margin-top:15px;">
                <el-table-column label="检验转移（放宽>>>正常>>>加严）" align="center">
                    <el-table-column label="检验数量（台）" align="center" width="130">
                        <template slot-scope="scope">
                            <el-input v-model.number="scope.row.inspectionQuantityConditionStricter" autosize style="width: 100px"/>
                        </template>
                    </el-table-column>
                    <el-table-column label="检验时间（天）" align="center" width="130">
                        <template slot-scope="scope">
                            <el-input v-model.number="scope.row.inspectionTimeConditionStricter" autosize style="width: 100px"/>
                        </template>
                    </el-table-column>
                    <el-table-column label="不良数量（台）" align="center" width="130">
                        <template slot-scope="scope">
                            <el-input v-model.number="scope.row.badQuantityConditionStricter" autosize style="width: 100px"/>
                        </template>
                    </el-table-column>
                </el-table-column>
                <el-table-column  label="检验转移（加严>>>正常>>>放宽）" align="center">
                  <el-table-column label="检验数量（台）" align="center" width="130">
                      <template slot-scope="scope">
                          <el-input v-model.number="scope.row.inspectionQuantityConditionBroaden" autosize style="width: 100px"/>
                        </template>
                    </el-table-column>
                    <el-table-column label="检验时间（天）" align="center" width="130">
                        <template slot-scope="scope">
                            <el-input v-model.number="scope.row.inspectionTimeConditionBroaden" autosize style="width: 100px"/>
                        </template>
                    </el-table-column>
                    <el-table-column label="不良数量（台）" align="center" width="130">
                        <template slot-scope="scope">
                            <el-input v-model.number="scope.row.badQuantityConditionBroaden" autosize style="width: 100px"/>
                        </template>
                    </el-table-column>
                </el-table-column>
            </el-table>
        </div>
        <!-- 公共底部 -->
        <div slot="footer" class="dialog-footer">
            <el-button @click="showAdd = false">取 消</el-button>
            <el-button
            type="primary"
            @click="addfacility('createForm')"
            >新增</el-button
            >
        </div>
    </el-dialog>


    <div class="filter-container">
      <!-- style="width: 150px;margin-right:15px;" -->

        <el-select v-model="param.workCenter" placeholder="请选择工作中心" class="ul-item" filterable clearable style="margin-right: 15px;width: 150px">
            <el-option v-for="(item,index) in workCenterList" :key="index" :label="item" :value="item"> </el-option>
        </el-select>

        <el-select v-model="param.inspectionLink" placeholder="请选择检验环节" class="ul-item" filterable clearable style="margin-right: 15px;width: 150px">
            <el-option v-for="(item,index) in inspectionLinkList" :key="index" :label="item" :value="item"> </el-option>
        </el-select>

        <el-input
            @keyup.enter.native="getData"
            clearable
            style="margin-right: 15px;width: 150px"
            v-model="param.codingClass"
            placeholder="请输入编码类型"
        ></el-input>

        <el-select v-model="param.inspectionMethod" placeholder="请选择检验方式" class="ul-item" filterable clearable style="margin-right: 15px;width: 150px">
            <el-option v-for="(item,index) in checkoutList" :key="index" :label="item" :value="item"> </el-option>
        </el-select>

        <el-select v-model="param.samplingStatus" placeholder="请选择抽检状态" class="ul-item" filterable clearable style="margin-right: 15px;width: 150px">
            <el-option v-for="(item,index) in samplingStatusList" :key="index" :label="item" :value="item"> </el-option>
        </el-select>

        <el-select v-model="param.checkList" placeholder="查检表是否启用" class="ul-item" filterable clearable style="margin-right: 15px;width: 150px">
            <el-option v-for="(item,index) in isStartList" :key="index" :label="item" :value="item"> </el-option>
        </el-select>

        <el-select v-model="param.mugShot" placeholder="是否需要拍照" class="ul-item" filterable clearable style="margin-right: 15px;width: 150px">
            <el-option v-for="(item,index) in whetherList" :key="index" :label="item" :value="item"> </el-option>
        </el-select>

        <el-select v-model="param.currentState" placeholder="请先择当前状态" class="ul-item" filterable clearable style="margin-right: 15px;width: 150px">
            <el-option v-for="(item,index) in isStartList" :key="index" :label="item" :value="item"> </el-option>
        </el-select>

        <el-button type="primary" v-waves icon="el-icon-search" @click="getData">搜索</el-button>
        <el-button
            type="button"
            v-waves
            class="el-button el-button--warning"
            @click="cancelSubmit"
        >
        重置</el-button>
    </div>

    <!-- table 表格 -->
    <el-table :data="tableInfo" v-loading="loadingList" element-loading-text="给我一首歌的时间" stripe border fit highlight-current-row style="width: 100%;margin-top:15px;">
      <el-table-column  label="序号" type="index" align="center" width="80px"/>
      <el-table-column label="工作中心"  prop="workCenter" align="center"/>
      <el-table-column label="检验环节"  prop="inspectionLink" align="center"/>
      <el-table-column label="编码类别"  prop="codingClass" align="center"/>
      <el-table-column label="检验方式"  prop="inspectionMethod" align="center"/>
      <el-table-column label="抽检状态"  prop="samplingStatus" align="center"/>
      <el-table-column label="数量大于"  prop="beGreaterThan" align="center"/>
      <el-table-column label="数量小于等于"  prop="quantityLe" align="center"/>
      <el-table-column label="放宽抽检数量"  prop="relaxTheNumberOfRandomInspections" align="center"/>
      <el-table-column label="正常抽检数量"  prop="normalSamplingQuantity" align="center"/>
      <el-table-column label="加严抽检数量"  prop="increaseTheNumberOfRandomInspections" align="center"/>
      <el-table-column label="检验转移（放宽>>>正常>>>加严）" align="center">
          <el-table-column label="检验数量条件"  prop="inspectionQuantityConditionStricter" align="center"/>
          <el-table-column label="检验时间条件"  prop="inspectionTimeConditionStricter" align="center"/>
          <el-table-column label="不良数量条件"  prop="badQuantityConditionStricter" align="center"/>
      </el-table-column>
      <el-table-column label="检验转移（加严>>>正常>>>放宽）" align="center">
          <el-table-column label="检验数量条件"  prop="inspectionQuantityConditionBroaden" align="center"/>
          <el-table-column label="检验时间条件"  prop="inspectionTimeConditionBroaden" align="center"/>
          <el-table-column label="不良数量条件"  prop="badQuantityConditionBroaden" align="center"/>
      </el-table-column>
      <el-table-column label="查检表"  prop="checkList" align="center"/>
      <el-table-column label="查检方式"  prop="inspectionMode" align="center"/>
      <el-table-column label="拍照存档"  prop="mugShot" align="center"/>
      <el-table-column label="拍照方式"  prop="photoMethod" align="center"/>
      <el-table-column label="抄送人"  prop="carbonCopyRecipientsUserName" align="center" width="130" show-overflow-tooltip/>
      <el-table-column label="修改人"  prop="updateJobNumber" align="center"/>
      <el-table-column label="修改时间"  prop="updateTime" align="center"/>
      <el-table-column label="当前状态"  prop="currentState" align="center">
        <template slot-scope="scope" >
            <el-switch v-model="scope.row.currentState" @change="updState(scope.row)" active-value="1" inactive-value="0" />
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" width="130">
        <template slot-scope="scope" >
            <div class="fx" style="display: flex">
                <el-button size="mini" type="primary" @click="handleEdit(scope.row)">修改</el-button>
                <el-button
                    icon="el-icon-delete"
                    class="el-button el-button--danger"
                    style="font-size: 15px;"
                    @click="handleDelete(scope.row,scope.$index)"
                ></el-button>
            </div>
        </template>
      </el-table-column>
    </el-table>

    <!-- 修改数据弹窗 -->
    <el-dialog
      title="修改工序信息"
      :visible.sync="showupd"
      @close="closeUpd"
      width="70%"
    >
    <el-form :model="updForm" :inline="true" ref="updForm" :rules="addRules">
            <div style="display: flex;">
                <el-form-item label="工作中心" prop="workCenter" label-width="120px">
                    <el-select
                        v-model="updForm.workCenter" 
                        disabled
                        clearable
                        filterable
                        placeholder="请选择工作中心"
                        class="ul-item">
                        <el-option :value="item" :label="item" v-for="(item,index) in this.workCenterList" :key="index"/>
                    </el-select>
                </el-form-item>
                <el-form-item label="检验环节" prop="inspectionLink" label-width="120px">
                    <el-select 
                        v-model="updForm.inspectionLink" 
                        disabled
                        clearable
                        filterable
                        placeholder="请先择检验环节"
                        class="ul-item">
                        <el-option :value="item" :label="item" v-for="(item,index) in this.processList" :key="index"/>
                    </el-select>
                    <!-- <el-input v-model="updForm.inspectionLink"  placeholder="请先择检验环节" autosize style="width: 150px"/> -->
                </el-form-item>
                <el-form-item label="编码类别" prop="codingClass" label-width="120px">
                    <el-input v-model="updForm.codingClass" disabled  placeholder="请输入编码类别" autosize style="width: 150px"/>
                </el-form-item>
                <el-form-item label="检验方式" prop="inspectionMethod" label-width="120px">
                    <el-select v-model="updForm.inspectionMethod" placeholder="请选择检验方式" class="ul-item" filterable clearable style="width: 150px">
                      <el-option v-for="(item,index) in checkoutList" :key="index" :label="item" :value="item"> </el-option>
                    </el-select>
                </el-form-item>
            </div>
            <div style="display: flex;">
                <el-form-item label="抽检状态" prop="samplingStatus" v-if="updForm.inspectionMethod != '全检'" label-width="120px">
                    <el-select v-model="updForm.samplingStatus" :disabled="disabledState" placeholder="请选择抽检状态" class="ul-item" filterable clearable style="width: 150px">
                        <el-option v-for="(item,index) in samplingStatusList" :key="index" :label="item" :value="item"> </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="查检表" prop="checkList" label-width="120px">
                    {{ '停用' }}
                    <el-switch  v-model="updForm.checkList" active-value="启用" inactive-value="停用" />
                    {{ '启用' }}
                </el-form-item>
                <el-form-item label="查检方式" v-if="updForm.checkList == '启用'" prop="inspectionMode">
                    <el-select v-model="updForm.inspectionMode" placeholder="请选择查检方式" class="ul-item" filterable clearable style="width: 150px">
                        <el-option v-for="(item,index) in InspectionList" :key="index" :label="item" :value="item"> </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="拍照存档" prop="mugShot" label-width="120px">
                    {{ '否' }}
                    <el-switch  v-model="updForm.mugShot" active-value="是" inactive-value="否" />
                    {{ '是' }}
                </el-form-item>
                <el-form-item label="拍照方式" v-if="updForm.mugShot == '是'" prop="photoMethod">
                    <el-select v-model="updForm.photoMethod" placeholder="拍照方式" class="ul-item" filterable clearable style="width: 130px">
                        <el-option v-for="(item,index) in InspectionList" :key="index" :label="item" :value="item"> </el-option>
                    </el-select>
                </el-form-item>
            </div>
            <el-link v-if="updForm.inspectionMethod != '全检'" :underline="false">抽检方案维护</el-link>
            <div style="display: flex">
            <div v-if="updForm.inspectionMethod != '全检'" style="width: 800px;margin-top:15px;">
                <el-table :data="SchemeUpdList" stripe border fit highlight-current-row style="width: 100%;margin-top:15px;">
                    <el-table-column  label="序号" type="index" align="center" width="50px"/>
                    <el-table-column label="数量大于" align="center" width="130">
            <template slot-scope="scope">
                <el-input v-model="scope.row.beGreaterThan" autosize style="width: 100px"/>
            </template>
        </el-table-column>
          <el-table-column label="数量小于等于" align="center" width="130">
              <template slot-scope="scope">
                  <el-input v-model="scope.row.quantityLe" autosize style="width: 100px"/>
                </template>
        </el-table-column>
          <el-table-column label="放宽检验数量" align="center" width="130">
              <template slot-scope="scope">
                <el-input v-model="scope.row.relaxTheNumberOfRandomInspections" autosize style="width: 100px"/>
            </template>
        </el-table-column>
        <el-table-column label="正常检验数量" align="center" width="130">
            <template slot-scope="scope">
                <el-input v-model="scope.row.normalSamplingQuantity" autosize style="width: 100px"/>
            </template>
        </el-table-column>
        <el-table-column label="加严检验数量" align="center" width="130">
            <template slot-scope="scope">
                <el-input v-model="scope.row.increaseTheNumberOfRandomInspections" autosize style="width: 100px"/>
            </template>
        </el-table-column>
    </el-table>
</div>
<el-form-item label="邮件抄送" label-width="80px">
    <div v-for="(items,index1) in MailUserName" :key="index1" style="margin-bottom: 5px;">
        <el-select  @change="mailChang($event,index1)" filterable @focus="businessFocus" v-model="items.name" placeholder="请选择" style="width:150px">
            <el-option
            v-for="(item,index) in personnelList"
            :key="index"
            :label="item.userName"
            :value="item.userName">
        </el-option>
    </el-select>
    <el-button style="margin-left: 5px;" type="danger" icon="el-icon-delete" circle @click="delMail(index1)"></el-button>
    <el-button v-if="index1 == 0" style="margin-left: 5px;" type="primary" icon="el-icon-plus" circle @click="addMail"></el-button>
</div>
</el-form-item>
</div>
</el-form>
<div v-if="updForm.inspectionMethod != '全检'">
    <el-link :underline="false">检验转移方案</el-link>
    <el-table :data="transferUpd" stripe border fit highlight-current-row style="width: 100%;margin-top:15px;">
        <el-table-column label="检验转移（放宽>>>正常>>>加严）" align="center">
          <el-table-column label="检验数量（台）" align="center" width="130">
              <template slot-scope="scope">
                  <el-input v-model="scope.row.inspectionQuantityConditionStricter" autosize style="width: 100px"/>
                </template>
            </el-table-column>
            <el-table-column label="检验时间（天）" align="center" width="130">
                <template slot-scope="scope">
                    <el-input v-model="scope.row.inspectionTimeConditionStricter" autosize style="width: 100px"/>
                </template>
            </el-table-column>
            <el-table-column label="不良数量（台）" align="center" width="130">
                <template slot-scope="scope">
                    <el-input v-model="scope.row.badQuantityConditionStricter" autosize style="width: 100px"/>
                </template>
            </el-table-column>
        </el-table-column>
        <el-table-column  label="检验转移（加严>>>正常>>>放宽）" align="center">
          <el-table-column label="检验数量（台）" align="center" width="130">
              <template slot-scope="scope">
                  <el-input v-model="scope.row.inspectionQuantityConditionBroaden" autosize style="width: 100px"/>
                </template>
            </el-table-column>
            <el-table-column label="检验时间（天）" align="center" width="130">
                <template slot-scope="scope">
                    <el-input v-model="scope.row.inspectionTimeConditionBroaden" autosize style="width: 100px"/>
                </template>
            </el-table-column>
            <el-table-column label="不良数量（台）" align="center" width="130">
                <template slot-scope="scope">
                    <el-input v-model="scope.row.badQuantityConditionBroaden" autosize style="width: 100px"/>
                </template>
            </el-table-column>
        </el-table-column>
    </el-table>
</div>
        <!-- 公共底部 -->
        <div slot="footer" class="dialog-footer">
            <el-button @click="showupd = false">取 消</el-button>
            <el-button
            type="primary"
            @click="updprocess('updForm')"
            >修改</el-button
            >
        </div>
    </el-dialog>

   <!-- pagination 分页 -->
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="listQuery.page"
        :page-sizes="[5,10, 20, 30, 40, 100, 300, 500]"
        :page-size="listQuery.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>

    <el-divider></el-divider>

    <el-button style="margin-right: 10px" type="success" size="small" @click="hExportExcel">导出数据Excel</el-button>

  </div>
</template>

<script>
import mixin from '@/utils/mixin.js'
import { groupProcessNo } from "@/api/processRoute"
import { findUserListGroup } from '@/api/chargingData'
import { inspectionSettingsSel,inspectionSettingsAdd,inspectionSettingsUpd,inspectionSettingsDel } from "@/api/checkSetting"
export default {
    name: 'inspectionSettings',
    mixins: [mixin],
    data () {
        return {
            srcURL:'',
            listQuery: {
                page: 1,                                    //页码
                limit: 10                                   //每页多少条记录
            },
            param: {
                code: '',                      
                content: ''                    
            },
            total: 0,                                      //数据的总数
            tableInfo: [],
            tableMX:[],
            showMX: false,
            loadingList: false,
            loading: false,
            centerList: ['装配车间','EMS总装车间'],                         //工作中心列表
            createForm: {},
            updForm: {},
            props: { multiple: true },
            // 表单校验
            addRules: {
                workCenter: [
                    { required: true, message: "工作中心不能为空!", trigger: "change" },
                ],
                inspectionLink: [
                    { required: true, message: "检验环节不能为空!", trigger: "blur" },
                ],
                codingClass: [
                    { required: true, message: "编码类别不能为空!", trigger: "change" },
                ],
                inspectionMethod: [
                    { required: true, message: "检验方式不能为空!", trigger: "change" },
                ],
                samplingStatus: [
                    { required: true, message: "抽检状态不能为空!", trigger: "change" },
                ],
                checkList: [
                    { required: true, message: "查检表不能为空!", trigger: "change" },
                ],
                inspectionMode: [
                    { required: true, message: "查检方式不能为空!", trigger: "change" },
                ],
                mugShot: [
                    { required: true, message: "拍照存档不能为空!", trigger: "change" },
                ],
                photoMethod: [
                    { required: true, message: "拍照方式不能为空!", trigger: "change" },
                ],
            },
            showAdd: false,
            showupd: false,
            userInfo: this.$store.state.user.userInfo,
            checkoutList:['全检','抽检'],
            samplingStatusList:['放宽检验','正常检验','加严检验'],
            isStartList:['启用','停用'],
            whetherList:['是','否'],
            InspectionList:['首台','全部'],
            SchemeList:[{}],
            transfer:[{}],         // 检验转移列表
            SchemeUpdList:[{}],
            transferUpd:[{}],
            workCenterList:[],
            inspectionLinkList:[],
            MailUserName:[{name:''}],
            personnelList:[],
            disabledState:false,
            processList:['FQC检验','OQC检验','OBA检验']
        }
    },
    computed: {
      inputWid() {
        return function (value) {
            if(!value || (value.length <= 10)){
              return '150px'    
            } else {
              return (150 + (String(value).length-10)*6) + 'px'
            }
        }
      }
    },
    methods: {
        // 修改框消失
        closeUpd(){ 
            this.showupd = false
            this.MailUserName = [{name:''}]
        },
          // 添加邮箱
      addMail(){
        if(!this.MailUserName[this.MailUserName.length -1].name){
                return this.$message.warning('请先选择人员')
            }
            this.MailUserName.push({name:''})
      },
          // 删除邮箱
      delMail(index){ 
        if(this.MailUserName.length == 1){
          this.MailUserName = [{name:''}]
        } else {
          this.MailUserName.splice(index, 1);
        }
      },
          // 邮箱发生改变
      mailChang(e,index1){
        this.personnelList.forEach(item => {
          if(e){
            if(e == item.userName){
                console.log(item)  
              if(item.mail && item.mail != 'null'){
                    this.MailUserName[index1].name = item.userName
                    this.MailUserName[index1].mail = item.mail
                    this.MailUserName[index1].jobNumber = item.jobNumber
              } else {
                  this.$message({
                    message: `${e}没有添加邮箱！`,
                    type: 'warning'
                  })    
                  this.MailUserName[index1].name = ''
                  this.MailUserName[index1].mail = ''
                  this.MailUserName[index1].jobNumber = ''
              }
            }
          }
        })
      },
        // 获取员工列表
        async businessFocus(){
        if(!this.personnelList.length) {
          const res = await findUserListGroup({page:1,limit:9999,status: 1})
          this.personnelList = res.data 
        }
      },
        // 修改状态
        async updState(row){
            const data = await inspectionSettingsUpd({id:row.id,currentState:row.currentState})
            let errmsg = data.msg
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errmsg)
            this.$message.success(errmsg)
        },
        // 方案维护新增
        SchemeAdd(){
            if(this.SchemeList.length == 5) return this.$message.warning('最多只能维护5条')
            this.SchemeList.push({})
        },
        // 方案维护删除
        SchemeDel(index,row){
            if(this.SchemeList.length == 1){
                this.SchemeList = [{}]
            }else{
                this.SchemeList.splice(index,1)
            }
        },
        getData(){
          this.listQuery.page = 1
          this.listQuery.limit = 10
          this.handleFilter()
        },
        async handleFilter() {
            this.loadingList = true
            let query = Object.assign({},this.listQuery)
            if(this.param.workCenter){ query.workCenter = this.param.workCenter}
            if(this.param.inspectionLink){ query.inspectionLink = this.param.inspectionLink}
            if(this.param.codingClass){ query.codingClass = this.param.codingClass}
            if(this.param.inspectionMethod){ query.inspectionMethod = this.param.inspectionMethod}
            if(this.param.samplingStatus){ query.samplingStatus = this.param.samplingStatus}
            if(this.param.checkList){ query.checkList = this.param.checkList}
            if(this.param.mugShot){ query.mugShot = this.param.mugShot}
            if(this.param.currentState){ query.currentState = this.param.currentState}
            let data = await inspectionSettingsSel(query)
            let errmsg = data.msg
            this.loadingList = false
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errmsg)
            this.total = data.data.count
            this.tableInfo = data.data.list
        },
        // table表单下方的页码组件改变每页显示的数据条数
        handleSizeChange(val) {
          this.listQuery.limit = val
          this.handleFilter()
        },
        // table表单下方的页码组件改变页面
        handleCurrentChange(val) {
          this.listQuery.page = val
          this.handleFilter()
        },
        transformDat(res) {
          const mapInfo = {
            index: '序号',
            workCenter: '工作中心',
            inspectionLink: '检验环节',
            codingClass: '编码类别',
            inspectionMethod: '校验方式',
            samplingStatus: '抽检状态',
            beGreaterThan: '数量大于',
            quantityLe: '数量小于等于',
            relaxTheNumberOfRandomInspections: '放宽抽检数量',
            normalSamplingQuantity: '正常抽检数量',
            increaseTheNumberOfRandomInspections: '加严抽检数量',
            inspectionQuantityConditionStricter: '(放宽>正常>加严)检验数量条件',
            inspectionTimeConditionStricter: '(放宽>正常>加严)检验时间条件',
            badQuantityConditionStricter: '(放宽>正常>加严)不良数量条件',
            inspectionQuantityConditionBroaden: '(加严>正常>放宽)检验数量条件',
            inspectionTimeConditionBroaden: '(加严>正常>放宽)检验时间条件',
            badQuantityConditionBroaden: '(加严>正常>放宽)不良数量条件',
            checkList: '查检表',
            inspectionMode: '查检方式',
            mugShot: '拍照存档',
            photoMethod: '拍照方式',
            currentState: '当前状态',
            updateJobNumber: '修改人',
            updateTime: '修改时间',
          }
          // 对data进行格式化
          // 取出所有的属性名
          const props = Object.keys(res[0]) // ['id','']
          // 将属性名从英文转为中文
          const header = props.map(zhkey => mapInfo[zhkey])
          console.log('中文的表头', header)
          // const data=[['xxxx','总裁办'，'13800000']]
          const data = res.map(obj => Object.values(obj))
          return { header, data }
        },
        handleDelete(row,index) {
            this.$confirm('这将会永久删除该行数据，是否继续?', '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.delprocess(row,index)
            }).catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消删除'
                })
            })
        },
        async delprocess(row,index){
          let res = await inspectionSettingsDel({id: row.id})
          if(res.code == '500') return
          if(res.code != '1') return this.$message.error(res.msg)
          this.tableInfo.splice(index,1)
          this.$message.success(res.msg)
        },
        // 导出excel
        async hExportExcel() {
          this.loading = true
          let query = Object.assign({},this.listQuery)
          query.page = 1
          query.limit = 10000
          if(this.param.workCenter){ query.workCenter = this.param.workCenter}
          if(this.param.inspectionLink){ query.inspectionLink = this.param.inspectionLink}
          if(this.param.codingClass){ query.codingClass = this.param.codingClass}
          if(this.param.inspectionMethod){ query.inspectionMethod = this.param.inspectionMethod}
          if(this.param.samplingStatus){ query.samplingStatus = this.param.samplingStatus}
          if(this.param.checkList){ query.checkList = this.param.checkList}
          if(this.param.mugShot){ query.mugShot = this.param.mugShot}
          if(this.param.currentState){ query.currentState = this.param.currentState}
          let arr = await inspectionSettingsSel(query)
          if(arr.code == '500') return
          if(arr.code != '1'){
            this.loading = false
            return this.$message.error(errmsg)
          }
          if(!arr.data.list.length){
            this.loading = false
            this.$message.error('暂无数据')
          }
          const { header, data } = this.transformDat(this.setSort(arr.data.list))
          import('@/vendor/Export2Excel').then(excel => {
            // excel表示导入的模块对象
            console.log(excel)
            excel.export_json_to_excel({
            header, // 表头 必填
            data, // 具体数据 必填
            filename: '制程检验设置', // 文件名称
            autoWidth: true, // 宽度是否自适应
            bookType: 'xlsx' // 生成的文件类型
            })
          })
          this.loading = false
        },
        // 排序函数
        setSort(arr){
          let newArr = JSON.parse(JSON.stringify(arr))
          let arr1 = []
          newArr.forEach((item,index)=>{
            let obj = {
              index: index+1,
              workCenter: item.workCenter,
              inspectionLink: item.inspectionLink,
              codingClass: item.codingClass,
              inspectionMethod: item.inspectionMethod,
              samplingStatus: item.samplingStatus,
              beGreaterThan: item.beGreaterThan,
              quantityLe: item.quantityLe,
              relaxTheNumberOfRandomInspections: item.relaxTheNumberOfRandomInspections,
              normalSamplingQuantity: item.normalSamplingQuantity,
              increaseTheNumberOfRandomInspections: item.increaseTheNumberOfRandomInspections,
              inspectionQuantityConditionStricter: item.inspectionQuantityConditionStricter,
              inspectionTimeConditionStricter: item.inspectionTimeConditionStricter,
              badQuantityConditionStricter: item.badQuantityConditionStricter,
              inspectionQuantityConditionBroaden: item.inspectionQuantityConditionBroaden,
              inspectionTimeConditionBroaden: item.inspectionTimeConditionBroaden,
              badQuantityConditionBroaden: item.badQuantityConditionBroaden,
              checkList: item.checkList,
              inspectionMode: item.inspectionMode,
              mugShot: item.mugShot,
              photoMethod: item.photoMethod,
              currentState: item.currentState,
              updateJobNumber: item.updateJobNumber,
              updateTime: item.updateTime,
            }
            arr1.push(obj)
          })
          return arr1
        },
        cancelSubmit(){
            this.param = {
                code: '',           
                content: '',      
            }
            this.listQuery.page = 1
            this.handleFilter()
        },
        // 提交表单之前先进行验证
        addfacility(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.submitprocess()
                } else {
                    return false
                }
            })
        },
        async submitprocess(){
            // 校验抽检方案
            if(this.createForm.inspectionMethod != '全检'){
                for(const item of this.SchemeList){
                    if(!item.beGreaterThan && item.beGreaterThan != 0) return this.$message.warning('抽检方案请维护完整！')
                    if(!item.quantityLe && item.quantityLe != 0) return this.$message.warning('抽检方案请维护完整！')
                    if(!item.relaxTheNumberOfRandomInspections && item.relaxTheNumberOfRandomInspections != 0) return this.$message.warning('抽检方案请维护完整！')
                    if(!item.normalSamplingQuantity && item.normalSamplingQuantity != 0) return this.$message.warning('抽检方案请维护完整！')
                    if(!item.increaseTheNumberOfRandomInspections && item.increaseTheNumberOfRandomInspections != 0) return this.$message.warning('抽检方案请维护完整！')
                }
                // 检验转移方案
                for(const item of this.transfer){
                    if(!item.inspectionQuantityConditionStricter && item.inspectionQuantityConditionStricter != 0) return this.$message.warning('检验转移方案维护完整！')
                    if(!item.inspectionTimeConditionStricter && item.inspectionTimeConditionStricter != 0) return this.$message.warning('检验转移方案维护完整！')
                    if(!item.badQuantityConditionStricter && item.badQuantityConditionStricter != 0) return this.$message.warning('检验转移方案维护完整！')
                    if(!item.inspectionQuantityConditionBroaden && item.inspectionQuantityConditionBroaden != 0) return this.$message.warning('检验转移方案维护完整！')
                    if(!item.inspectionTimeConditionBroaden && item.inspectionTimeConditionBroaden != 0) return this.$message.warning('检验转移方案维护完整！')
                    if(!item.badQuantityConditionBroaden && item.badQuantityConditionBroaden != 0) return this.$message.warning('检验转移方案维护完整！')
                    // if(!item.inspectionTimeConditionStricter || !item.badQuantityConditionStricter || !item.inspectionQuantityConditionBroaden || !item.inspectionTimeConditionBroaden || !item.badQuantityConditionBroaden){
                    //     return this.$message.warning('检验转移方案维护完整！')
                    // }
                }
            }
            // 校验抄送人
            for(const item of this.MailUserName){
                if(this.MailUserName.length > 1){
                    if(!item.name){
                        return this.$message.warning('请维护抄送人员！')
                    }
                }
            }
            if(this.createForm.workCenter == 'EMS总装车间'){
                if(this.createForm.inspectionLink == '检验' || this.createForm.inspectionLink == 'OQC终检') return this.$message.warning('EMS总装车间必须维护 整机终检或OBA检验！')
            }
            if(this.createForm.workCenter == '装配车间'){
                if(this.createForm.inspectionLink == '整机终检' || this.createForm.inspectionLink == 'OBA检验') return this.$message.warning('装配车间必须维护 检验或OQC终检！')
            }
            if(this.createForm.checkList == '停用'){
                this.createForm.inspectionMode = ''
            }
            if(this.createForm.mugShot == '否'){
                this.createForm.photoMethod = ''
            }
            let query = Object.assign({},this.createForm)
            console.log(query)
            const arr1 = this.MailUserName.map(item => item.name)
            const arr2 = this.MailUserName.map(item => item.jobNumber)
            const arr3 = this.MailUserName.map(item => item.mail)
            query.carbonCopyRecipientsUserName = arr1.join()
            query.carbonCopyRecipientsJobNumber = arr2.join()
            query.carbonCopyRecipientsMail = arr3.join(';')   // 邮箱用 ; 分开
            if(this.createForm.inspectionMethod == '全检'){
                query.samplingStatus = null
                const data = await inspectionSettingsAdd(query)
                const errMsg = data.msg
                if(data.code == '500') return
                if(data.code != '1') return this.$message.error(errMsg)
                this.$message.success(errMsg)
            }else {
                query.inspectionQuantityConditionStricter = this.transfer[0].inspectionQuantityConditionStricter
                query.inspectionTimeConditionStricter = this.transfer[0].inspectionTimeConditionStricter
                query.badQuantityConditionStricter = this.transfer[0].badQuantityConditionStricter
                query.inspectionQuantityConditionBroaden = this.transfer[0].inspectionQuantityConditionBroaden
                query.inspectionTimeConditionBroaden = this.transfer[0].inspectionTimeConditionBroaden
                query.badQuantityConditionBroaden = this.transfer[0].badQuantityConditionBroaden
                console.log('query',query)
                for(const item of this.SchemeList){
                    query.beGreaterThan = item.beGreaterThan
                    query.quantityLe = item.quantityLe
                    query.relaxTheNumberOfRandomInspections = item.relaxTheNumberOfRandomInspections
                    query.normalSamplingQuantity = item.normalSamplingQuantity
                    query.increaseTheNumberOfRandomInspections = item.increaseTheNumberOfRandomInspections
                    const data = await inspectionSettingsAdd(query)
                    const errMsg = data.msg
                    if(data.code == '500') return
                    if(data.code != '1') return this.$message.error(errMsg)
                    this.$message.success(errMsg)
                }
            }
            this.resetForm()
            this.SchemeList = [{}]
            this.transfer = [{}]
            this.MailUserName = [{name:''}]
            this.showAdd = false
            this.handleFilter()
        },
        resetForm(){
             this.$refs.createForm.resetFields();
        },
        handleEdit(row){
            this.updForm = Object.assign({},row)
            let arr1 = []
            let arr2 = []
            let arr3 = []
            if(row.carbonCopyRecipientsUserName){ arr1 = row.carbonCopyRecipientsUserName.split(',')}
            if(row.carbonCopyRecipientsJobNumber){ arr2 = row.carbonCopyRecipientsJobNumber.split(',')}
            if(row.carbonCopyRecipientsMail){ arr3 = row.carbonCopyRecipientsMail.split(';')}
            if(row.carbonCopyRecipientsUserName){
                this.MailUserName = arr1.map((item,index) => ({
                  name: item,
                  jobNumber: arr2[index],
                  mail: arr3[index],
                }))
            }
            console.log(this.MailUserName)
            this.$set(this.SchemeUpdList[0],'beGreaterThan',row.beGreaterThan)
            this.$set(this.SchemeUpdList[0],'quantityLe',row.quantityLe)
            this.$set(this.SchemeUpdList[0],'relaxTheNumberOfRandomInspections',row.relaxTheNumberOfRandomInspections)
            this.$set(this.SchemeUpdList[0],'normalSamplingQuantity',row.normalSamplingQuantity)
            this.$set(this.SchemeUpdList[0],'increaseTheNumberOfRandomInspections',row.increaseTheNumberOfRandomInspections)
            this.$set(this.transferUpd[0],'inspectionQuantityConditionStricter',row.inspectionQuantityConditionStricter)
            this.$set(this.transferUpd[0],'inspectionTimeConditionStricter',row.inspectionTimeConditionStricter)
            this.$set(this.transferUpd[0],'badQuantityConditionStricter',row.badQuantityConditionStricter)
            this.$set(this.transferUpd[0],'inspectionQuantityConditionBroaden',row.inspectionQuantityConditionBroaden)
            this.$set(this.transferUpd[0],'inspectionTimeConditionBroaden',row.inspectionTimeConditionBroaden)
            this.$set(this.transferUpd[0],'badQuantityConditionBroaden',row.badQuantityConditionBroaden)
            this.showupd = true
        },
        // 提交表单之前先进行验证
        updprocess(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.inspectionSettingsUpd()
                } else {
                    return false
                }
            })
        },
        async inspectionSettingsUpd(){
            if(this.updForm.inspectionMethod != '全检'){
                // 校验抽检方案
                for(const item of this.SchemeUpdList){
                    if(!item.beGreaterThan && item.beGreaterThan != 0) return this.$message.warning('抽检方案请维护完整！')
                    if(!item.quantityLe && item.quantityLe != 0) return this.$message.warning('抽检方案请维护完整！')
                    if(!item.relaxTheNumberOfRandomInspections && item.relaxTheNumberOfRandomInspections != 0) return this.$message.warning('抽检方案请维护完整！')
                    if(!item.normalSamplingQuantity && item.normalSamplingQuantity != 0) return this.$message.warning('抽检方案请维护完整！')
                    if(!item.increaseTheNumberOfRandomInspections && item.increaseTheNumberOfRandomInspections != 0) return this.$message.warning('抽检方案请维护完整！')
                    // if(!item.beGreaterThan || !item.quantityLe || !item.relaxTheNumberOfRandomInspections || !item.normalSamplingQuantity || !item.increaseTheNumberOfRandomInspections){
                    //     return this.$message.warning('抽检方案请维护完整！')
                    // }
                }
                // 检验转移方案
                for(const item of this.transferUpd){
                    if(!item.inspectionQuantityConditionStricter && item.inspectionQuantityConditionStricter != 0) return this.$message.warning('检验转移方案维护完整！')
                    if(!item.inspectionTimeConditionStricter && item.inspectionTimeConditionStricter != 0) return this.$message.warning('检验转移方案维护完整！')
                    if(!item.badQuantityConditionStricter && item.badQuantityConditionStricter != 0) return this.$message.warning('检验转移方案维护完整！')
                    if(!item.inspectionQuantityConditionBroaden && item.inspectionQuantityConditionBroaden != 0) return this.$message.warning('检验转移方案维护完整！')
                    if(!item.inspectionTimeConditionBroaden && item.inspectionTimeConditionBroaden != 0) return this.$message.warning('检验转移方案维护完整！')
                    if(!item.badQuantityConditionBroaden && item.badQuantityConditionBroaden != 0) return this.$message.warning('检验转移方案维护完整！')
                    // if(!item.inspectionQuantityConditionStricter || !item.inspectionTimeConditionStricter || !item.badQuantityConditionStricter || !item.inspectionQuantityConditionBroaden || !item.inspectionTimeConditionBroaden || !item.badQuantityConditionBroaden){
                    //     return this.$message.warning('检验转移方案维护完整！')
                    // }
                }
            }
            // 检验抄送人
            for(const item of this.MailUserName){
                if(this.MailUserName.length > 1){
                    if(!item.name){
                        return this.$message.warning('请维护抄送人员！')
                    }
                }
            }
            if(this.updForm.checkList == '停用'){
                this.updForm.inspectionMode = ''
            }
            if(this.updForm.mugShot == '否'){
                this.updForm.photoMethod = ''
            }
            let query = Object.assign({},this.updForm)
            const arr1 = this.MailUserName.map(item => item.name)
            const arr2 = this.MailUserName.map(item => item.jobNumber)
            const arr3 = this.MailUserName.map(item => item.mail)
            query.carbonCopyRecipientsUserName = arr1.join()
            query.carbonCopyRecipientsJobNumber = arr2.join()
            query.carbonCopyRecipientsMail = arr3.join(';')   // 邮箱用 ; 分开
            if(this.updForm.inspectionMethod == '全检'){
                query.samplingStatus = ''
                query.beGreaterThan = ''
                query.quantityLe = ''
                query.relaxTheNumberOfRandomInspections = ''
                query.normalSamplingQuantity = ''
                query.increaseTheNumberOfRandomInspections = ''
                query.inspectionQuantityConditionStricter = ''
                query.inspectionTimeConditionStricter = ''
                query.badQuantityConditionStricter = ''
                query.inspectionQuantityConditionBroaden = ''
                query.inspectionTimeConditionBroaden = ''
                query.badQuantityConditionBroaden = ''
            }else{
                query.beGreaterThan = this.SchemeUpdList[0].beGreaterThan
                query.quantityLe = this.SchemeUpdList[0].quantityLe
                query.relaxTheNumberOfRandomInspections = this.SchemeUpdList[0].relaxTheNumberOfRandomInspections
                query.normalSamplingQuantity = this.SchemeUpdList[0].normalSamplingQuantity
                query.increaseTheNumberOfRandomInspections = this.SchemeUpdList[0].increaseTheNumberOfRandomInspections
                query.inspectionQuantityConditionStricter = this.transferUpd[0].inspectionQuantityConditionStricter
                query.inspectionTimeConditionStricter = this.transferUpd[0].inspectionTimeConditionStricter
                query.badQuantityConditionStricter = this.transferUpd[0].badQuantityConditionStricter
                query.inspectionQuantityConditionBroaden = this.transferUpd[0].inspectionQuantityConditionBroaden
                query.inspectionTimeConditionBroaden = this.transferUpd[0].inspectionTimeConditionBroaden
                query.badQuantityConditionBroaden = this.transferUpd[0].badQuantityConditionBroaden
            }
            delete query.createTime
            delete query.updateTime
            const data = await inspectionSettingsUpd(query)
            const errMsg = data.msg
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errMsg)
            this.showupd = false
            this.SchemeList = [{}]
            this.transfer = [{}]
            this.MailUserName = [{name:''}]
            this.handleFilter()
            this.$message.success(errMsg)
        },
        addInOrOut(){
            this.showAdd = true
        },
        // 获取可先的工作中心和	检验环节
        async getList(){
            let res = await inspectionSettingsSel({page:1,limit:9999})
            console.log('res',res);
            const workCenter = res.data.list.map(item => item.workCenter)
            const inspectionLink = res.data.list.map(item => item.inspectionLink)
            this.workCenterList = [...new Set(workCenter)]
        }
    },
    // 进入页面获取table信息
    mounted() {
        this.handleFilter()
        this.getList()
        // 判断 质量总监 和 管理员才能修改 抽检状态
        if(this.userInfo.roleId == 24 || this.userInfo.roleId == 14){
            this.disabledState = false
        }else{
            this.disabledState = true
        }
    }
}
</script>

<style>

.btn-add{
    margin-bottom: 28px;
}

.ul-item{
  width: 85%;
}
</style>
